package config

import (
	"database/sql"
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var Db *sql.DB

func InitDb(driverName, dsn string) error {

	var err error
	Db, err = sql.Open(driverName, dsn)
	if err != nil {
		fmt.Println(err)
		return err
	}
	if err = Db.Ping(); err != nil {
		fmt.Println(err)
		return err
	}
	return nil
}

func CloseDB() error {
	return Db.Close()
}
